//
//  LSZKnowChristVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/9/30.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZKnowChristVC.h"

@interface LSZKnowChristVC ()

@end

@implementation LSZKnowChristVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self RequestResolution];
}
-(void)RequestResolution
{
     __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic initWithKnowChrist:[NSString stringWithFormat:@"%zd",(long)weakSelf.act ] id_id:weakSelf.id_id :^(BOOL isOK, NSString * str, LSZKnowChristManager * ChristManager) {
        if (isOK == YES) {
            weakSelf.KnowMutArray = [[NSMutableArray alloc]initWithArray:ChristManager.mutDataArray];
            [weakSelf.tableviewKnowChrist reloadData];
        }else{
            [self addHubPromptMessage:str];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"了解基督";
    [self.tableviewKnowChrist registerClass:[LSZKnowChristTableViewCell class] forCellReuseIdentifier:@"LSZKnowChristTableViewCell"];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.tabBarController.tabBar.translucent = NO;
    [self setupTableViewLayout];
}
- (void)setupTableViewLayout
{
    [self.tableviewKnowChrist mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.view);
        if (@available(iOS 11, *)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-0);
        }else{
            make.top.equalTo(self.view.mas_top);
            make.bottom.equalTo(self.view.mas_bottom).offset(-0);
        }
    }];
}
- (void)setupTableViewCompatibilityADLayout
{
    CGFloat width = MIN(self.view.width , self.view.height);
    [self.tableviewKnowChrist mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.view);
        if (@available(iOS 11, *)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-width/20*3);
        }else{
            make.top.equalTo(self.view.mas_top);
            make.bottom.equalTo(self.view.mas_bottom).offset(-width/20*3);
        }
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.KnowMutArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZKnowChristTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZKnowChristTableViewCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[LSZKnowChristTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LSZKnowChristTableViewCell"];
    }
    LSZKnowChristMg * KnowMg = nil;
    KnowMg = self.KnowMutArray[indexPath.row];
    cell.labelTitle.text = [NSString stringWithFormat:@"%@",KnowMg.title];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZKnowChristMg * KnowMg = nil;
    KnowMg = self.KnowMutArray[indexPath.row];
    //最后一个跳转到H5界面
    if ([self.comeToNextPage isEqualToString:@"1"]) {
        LSZWebViewVC * vc = [[LSZWebViewVC alloc]init];
        vc.titleStr = KnowMg.title;
        vc.url = KnowMg.url;
        [self.navigationController pushViewController:vc animated:YES];
    }
#pragma mark  如果hasChild 则再请求的数据   该加载h5界面
    else if ([KnowMg.hasChild isEqualToString:@"0"]) {
        LSZKnowChristVC * vc = [[LSZKnowChristVC alloc]init];
        vc.id_id = KnowMg.id_id;
        vc.act = self.act+1;
        vc.comeToNextPage = @"1";
        [self.navigationController pushViewController:vc animated:YES];
     }else{
        LSZKnowChristVC * vc = [[LSZKnowChristVC alloc]init];
        vc.id_id = KnowMg.id_id;
        vc.act = self.act+1;
        [self.navigationController pushViewController:vc animated:YES];
     }
}
-(UITableView *)tableviewKnowChrist
{
    if(_tableviewKnowChrist == nil){
        _tableviewKnowChrist = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
        _tableviewKnowChrist.dataSource = self;
        _tableviewKnowChrist.delegate = self;
        //添加以下代码关闭估算行高
        _tableviewKnowChrist.estimatedRowHeight = 0;
        _tableviewKnowChrist.estimatedSectionHeaderHeight = 0;
        _tableviewKnowChrist.estimatedSectionFooterHeight = 0;
        [_tableviewKnowChrist setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        //如果没有占满则清除下面的
        _tableviewKnowChrist.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        [self.view addSubview:_tableviewKnowChrist];
    }
    return _tableviewKnowChrist;
}
@end
